package day01;

/**
 * @Author Stringzhua
 * @Date 2024/10/29 10:06
 * description:线程的插队
 */
public class Test08 {
    private static void printThread(String text){
        System.out.println("[" + Thread.currentThread().getName() + "线程]" + text);
    }

    public static void main(String[] args) {
        printThread("开始执行main方法...");

        //创建子线程
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                printThread("进入子线程...");

                try {
                    printThread("我开始休眠了...");
                    Thread.sleep(1000);
                    printThread("子线程又被唤醒了...");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        try {
            //在主线程中启动子线程
            t1.start();
            printThread("在main方法中,等待下面这个线程执行完了才能继续往下执行");
            //子线程插队
//            t1.join();
//            t1.join(100);
            t1.join(1500);
            printThread("在main方法中即将退出...");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}
